<?php
/*=============================================================================
|| ##################################################################
||	phpFoX Konsort
|| ##################################################################
||	
||	Copyright		: (C) 2005-2007 PHPFOX Limited a Reality Fox Creation
||	Contact			: info@phpfox.com
||
||	- phpFoX and all of its source code and files are protected by Copyright Laws. 
||
||	- The license for phpFoX permits you to install this software on a single domain (.com, .org, .net, etc.). 
||
||	- You may also not remove this copyright screen which shows the copyright information and credits for phpFoX (RealityFOX Creations). 
||
||	- phpFoX Konsort is NOT a FREE software - http://www.phpfox.com/license/
||
|| ##################################################################
=============================================================================*/

/* $File: ./include/modules/Forum/classes/PhpFox_ComponentForumPath.class.php, $Author:  $ */



/** Forums path (breadcrumb) componment
 * 
 * Parameters:
 *   1. sType (option) - current page type: 'home' (default), 'topic', 'post'
 *   2. iId (optional for 'home') - topic or post ID
 * 
 * @package module.forum
 * @version $Id: PhpFox_ComponentForumPath.class.php 46 2007-12-14 23:12:21Z phpfoxsv $
 *   
 */
class PhpFox_Mod_Forum_ComponentForumPath extends BaseComponent
{

    /** Processing method
     */
	function process()
	{
	    
	    $oSrvForum = &$this->_oModule->getService('Forum');
	    /* @var $oSrvForum PhpFox_Mod_Forum_ServiceForum */
	    
	    $oTxt = App::newObject('Text');
	    
	    $sType = $this->getParam('sType', 'home');
	    $aPath = array();
	    $aPath[] = array('title' => App::format('core.forum.name'), 'url' => App::makeUrl('public.forum'));
	    $oReq = &App::getRequest();
	    
	    switch($sType)
	    {
	        case 'home':
	            break;
	            
	        case 'forum':
	            $iForumId = $oReq->getInt('id');
	            $oForum = &$this->_oModule->getItem('Forum');
	            /* @var $oForum PhpFox_Mod_Forum_ItemForum */
	            $oForum->load($iForumId);
        	    $aPath[] = array('title' => $oTxt->rmSpecialChars($oForum->aData['forum_title']),
        	                     'url' => App::makeUrl('public.forum.topics', array('id'=>$iForumId)) );
	            break;
	            
	        case 'topic':
	            $iTopicId = $oReq->getInt('id');
	            $oTopic = &$this->_oModule->getItem('ForumTopic');
	            $aRow = $oTopic->oDb->getRow('SELECT ft.title AS topic_title, f.forum_title AS forum_title, f.forum_id AS forum_id '.
                                             '  FROM '.$oTopic->sTable.' AS ft '.
	                                         '    INNER JOIN '.App::getT('forum').' AS f ON (ft.type = f.forum_id) '.
	                                         '  WHERE ft.id = '.$iTopicId);
	            if ($aRow)
	            {
            	    $aPath[] = array('title' => $aRow['forum_title'],
            	                     'url' => App::makeUrl('public.forum.topics', array('id'=>$aRow['forum_id'])) );
            	    $aPath[] = array('title' => $aRow['topic_title'],
            	                     'url' => App::makeUrl('public.forum.posts', array('id'=>$iTopicId)) );
	            }
	            break;
	    }

		$oTpl = &$this->_oModule->getTemplate();
		$oTpl->assign(array(
		    'aPath' => $aPath,
		));
		$srcHtml = $oTpl->fetch('ForumPath.html');
		return $srcHtml;
	}

}
?>